//
//  main.cpp
//  
//
//  Created by チョウ　コン on 2013/08/21.
//
//

#include <iostream>
#include <kvs/glut/Application>
#include <kvs/glut/Screen>
#include <kvs/glew/RayCastingRenderer>
#include <kvs/StructuredVolumeObject>
#include <kvs/StructuredVolumeImporter>
#include <kvs/CommandLine>
#include "Average.h"
#include "WriteStructuredVolume.h"

class Argument : public kvs::CommandLine
{
public:
    std::string data_type;
    std::string year;
    std::string month;
    
    Argument( int argc, char** argv ) : CommandLine( argc, argv )
    {
        add_help_option();
        addOption( "data", "data type", 1, true );
        addOption( "y", "year", 1, true );
        addOption( "m", "month", 1, true );
    }
    
    void exec()
    {
        if( !this->parse() ) exit( EXIT_FAILURE );
        if( this->hasOption( "data" ) ) data_type = this->optionValue<std::string>( "data" );
        if( this->hasOption( "y" ) ) year = this->optionValue<std::string>( "y" );
        if( this->hasOption( "m" ) ) month = this->optionValue<std::string>( "m" );
    }
    
};

int main( int argc, char** argv )
{
    kvs::glut::Application app( argc, argv );
    kvs::glut::Screen screen( &app );
    
    Argument param( argc, argv );
    param.exec();
    
    kvs::StructuredVolumeObject* volume = Average( param.data_type, param.year, param.month, 30 );
    WriteStructuredVolume( volume, param.data_type + "_" + param.year + param.month + ".kvsml" );
    
    exit( 0 );
    kvs::glew::RayCastingRenderer* renderer = new kvs::glew::RayCastingRenderer();
    screen.registerObject( volume, renderer );
    screen.show();
    
    return ( app.run() );
}
